package com.cefa.edu.dao;

import com.cefa.edu.model.Course;
import com.cefa.edu.pojo.Phase;
import org.apache.ibatis.annotations.*;

import java.util.HashMap;
import java.util.List;

/**
 *  教育阶段
 * @author huangzehui
 * @date 18-8-10 上午11:26
 */
@Mapper
public interface PhaseMapper {

    /**
     * @aa 根据教育学习阶段id 删除学习阶段数据
     * @aa add by chaijian 2018-08-15
     */
    @Update({"update cefa_edu_phase set state=1 where id=#{id} and state=0"})
    void deletePhaseById(Integer id);

    /**
     * @aa 根据教育学习阶段id 获取对应的教育学习阶段数据
     * @aa add by chaijian 2018-08-14
     */
    @Results(id = "phaseMapById", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "phaseName", column = "phase_name"),
            @Result(property = "sort", column = "sort"),
            @Result(property = "gradeCount", column = "grade_count"),
            @Result(property = "schoolId", column = "school_id"),
    })
    @Select({"select p.* from cefa_edu_phase p where p.id=#{id} and p.state=0"})
    Phase getPhaseById(Integer id);

    /**
     * @aa 根据学校id 获取对应的学习阶段数据
     * @aa 参数：学校id
     * @aa add by chaijian 2018-08-10
     */
    @Results(id = "phaseMapBySchoolId", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "phaseName", column = "phase_name"),
            @Result(property = "sort", column = "sort"),
            @Result(property = "gradeCount", column = "grade_count"),
            @Result(property = "schoolId", column = "school_id"),
    })
    @Select({"select p.* from cefa_edu_phase p where p.school_id=#{schoolId} and p.state=0"})
    List<HashMap<String,Object>> getPhasesBySchoolId(Integer schoolId);

    /**
     * @aa  添加学习阶段数据
     * @aa 参数：学习阶段中文字符
     * @aa add by chaijian 2018-08-10
     */
    @Insert({"insert INTO cefa_edu_phase(phase_name,school_id,sort,grade_count)values(#{phaseName},#{schoolId},#{sort},#{gradeCount})"})
    @Options(useGeneratedKeys = true,keyProperty = "id")
    int savePhase(Phase phase);

    @Select("select id,phase_name,sort,grade_count,school_id from cefa_edu_phase where state=0 and school_id=#{schoolId}")
    @Results(id = "phaseMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "phaseName", column = "phase_name"),
            @Result(property = "sort", column = "sort"),
            @Result(property = "gradeCount", column = "grade_count"),
            @Result(property = "schoolId", column = "school_id"),
    })
    List<Phase> findPhaseListBySchoolId(@Param("schoolId") Integer schoolId);

    @Select({"select id,phase_name,sort,grade_count,school_id,state from cefa_edu_phase  where id=#{id} and state=0"})
    @ResultMap(value="phaseMapById")
    Phase getPhaseById2(@Param("id") Integer id);
}
